package com.appcenter.application.controller;

import com.appcenter.application.input.userpicker.LoadUserPickerListPageInput;
import com.appcenter.application.input.userpicker.SearchUserPickerListInput;
import com.appcenter.application.service.UserPickerService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenterservice/UserPicker")
@Api("选择用户相关服务")
public class UserPickerServiceController {
    @Autowired
    UserPickerService userPickerService;

    @ApiOperation(value = "", notes = "", produces = "application/json")
    @PostMapping("/LoadUserPickerListPage")
    public ResponseEntity<JsonResult> LoadUserPickerListPage(@RequestBody LoadUserPickerListPageInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(userPickerService.LoadUserPickerListPage(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "", notes = "", produces = "application/json")
    @PostMapping("/SearchUserPickerList")
    public ResponseEntity<JsonResult> SearchUserPickerList(@RequestBody SearchUserPickerListInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(userPickerService.SearchUserPickerList(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
